package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.data.repository.query.Param;

import java.util.List;

@Mapper
public interface DishMapper {
    /**
     * 根据id修改菜品状态
     */
    @Update("update dish set status=#{status} where id=#{id}")
    void updateStatus(@Param("status")Integer status,@Param("id")Long id);
    /**
     * 动态条件查询菜品
     */
    List<Dish> list(Dish dish);
    /**
     * 查询菜品总数
     */
    @Select("select count(*) from dish")
    Integer getCount();
    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);
    /**
     * 像菜品表添加数据
     */
    @AutoFill(value = OperationType.INSERT)
    void addDish(Dish dish);
    /**
     * 分页条件查询菜品
     */
    Page<DishVO> pageGetDish(DishPageQueryDTO dishPageQueryDTO);
    /**
     * 根据id查询菜品信息
     */
    @Select("select * from dish where id=#{id}")
    Dish getDishById(@Param("id")Long id);
    /**
     * 根据id删除菜品
     */
    @Delete("delete from dish where id=#{id}")
    void deleteDishById(@Param("id")Long id);
    @AutoFill(value = OperationType.UPDATE)
    void update(Dish dish);
    /**
     * 根据分类id查询对应菜品
     */
    @Select("select * from dish where category_id=#{id}")
    List<Dish> getDishListByCategoryId(@Param("id")Long id);
    @Select("select a.* from dish a left join setmeal_dish b on a.id = b.dish_id where b.setmeal_id = #{setmealId}")
    List<Dish> getBySetmealId(Long setmealId);

}
